<?php
class connection {
	/**
	 * connect database server;
	 *
	 * @var $severName 服务器
	 * @var $userName 用户名
	 * @var $userPwd 密码
	 * @var $database 数据库
	 * @var $connection 数据库连接句柄
	 * @var $db 数据库连接句柄
	 */
	public static $severName ="localhost";
	public static $userName = "root";
	public static $userPwd = "";
	public static $database = "connection";
	public static $connection = false;
	public static $db = false;
	public function __construct(){
		$this->connection = connection::connectServer();
		$this->db = $this->selectDatabase();
	}
	/**
	 * 连接服务器并返回句柄
	 * 
	 */
	public static function connectServer(){
		$connect = mysql_connect(connection::$severName,connection::$userName,connection::$userPwd);
		return $connect;
	}
	/**
	 * 连接数据库
	 * 
	 */
	public function selectDatabase(){
		$connection = $this->connection;
		$datbase = connection::$database;
		//$datbase = "connection";
		if ($connection){
			$this->db = mysql_select_db($datbase,$connection);
			mysql_query('SET NAMES UTF8');
		}
	}	
}
$connection = new connection();
?>